package com.nefu.softlab.xjwc.mapper;

import com.nefu.softlab.xjwc.model.Score;
import com.nefu.softlab.xjwc.model.vo.ScoreVo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author : Ar1es
 * @date : 2020/2/8
 * @since : Java 8
 */
@Mapper
@Repository
public interface ScoreMapper {

    /**
     * 根据userId和projectId查询记录是否存在
     * @param score
     * @return
     */
    @Select("select count(*) from score where user_id = #{userId} and project_id = #{projectId}")
    int selectScoreIsExist(Score score);

    /**
     * 根据uprojectId查询记录是否存在
     * @param projectId
     * @return
     */
    @Select("select count(*) from score where project_id = #{projectId}")
    int selectScoreIsExistByProId(Integer projectId);

    /**
     * 根据userId和projectId查询分数
     * @param score
     * @return
     */
    @Select("select score from score where user_id = #{userId} and project_id = #{projectId}")
    double selectScore(Score score);

    /**
     * 根据项目查询分数列表
     * @param score
     * @return
     */
    List<ScoreVo> selectScoreByProject(Score score);


    /**
     * 根据userId和projectId查询他对这个项目的评分情况
     * @param score
     * @return
     */
    List<ScoreVo> selectSingleScoreByUserIdAndProId(Score score);

    /**
     * 根须项目查看多少人已经评分
     * @param score
     * @return
     */
    @Select("select count(*) from score where project_id = #{projectId}")
    int selectScoreNumberByProject(Score score);

    /**
     * 添加评分
     * @param score
     * @return
     */
    @Insert("insert into score(user_id, project_id, score, message) values(#{userId}, #{projectId}, #{score}, #{message})")
    int insertScore(Score score);

    /**
     * 修改评分
     * @param score
     * @return
     */
    int updateScore(Score score);

    /**
     * 删除评分
     * @param score
     * @return
     */
    @Delete("delete from score where score_id = #{scoreId}")
    int deleteScore(Score score);


    /**
     * 根据projectID删除评分
     * @param projectId
     * @return
     */
    @Delete("delete from score where project_id = #{arg0}")
    int deleteScoreByProjectId(Integer projectId);


}
